package com.yuanduan.mplus.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.cj.framework.app.BaseActivity;
import com.cj.framework.app.BaseApplication;
import com.cj.framework.util.SP;
import com.yuanduan.mplus.R;
import com.yuanduan.mplus.config.Config;
import com.yuanduan.mplus.model.DBManager;

public class Setting1Activity extends BaseActivity implements View.OnClickListener {
    //设置界面（意见反馈，退出登录，修改密码）
    private RelativeLayout rl_changePwd;
    private RelativeLayout rl_aboutUs;
    private LinearLayout ll_exit;
    private RelativeLayout rl_feedback;
    private Toolbar toolbar;

    @Override
    protected void findId() {
        rl_changePwd= (RelativeLayout) findViewById(R.id.setting1_rl_changePwd);
        rl_aboutUs= (RelativeLayout) findViewById(R.id.setting1_rl_aboutUs);
        ll_exit= (LinearLayout) findViewById(R.id.setting1_ll_exit);
        toolbar= (Toolbar) findViewById(R.id.toolbar);
        rl_feedback= (RelativeLayout) findViewById(R.id.setting1_rl_feedback);
    }

    @Override
    protected void logic() {
        toolbar.setTitle("设置");
        toolbar.setNavigationIcon(R.mipmap.back_arrow_black);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Setting1Activity.this.finish();
            }
        });

        rl_changePwd.setOnClickListener(this);
        rl_aboutUs.setOnClickListener(this);
        rl_feedback.setOnClickListener(this);
        ll_exit.setOnClickListener(this);
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_setting1;
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.setting1_rl_aboutUs:
                openActivity(AboutUsActivity.class);
                break;
            case R.id.setting1_rl_changePwd:
                openActivity(ChangePwdActivity.class);
                break;
            case R.id.setting1_ll_exit:
                //删除数据库内容
                BaseApplication.getDaoSession().getUserDao().deleteAll();
                //删除记住密码数据
                SP.delete("isRemember");
                SP.delete("rememberUserPhone");
                SP.delete("rememberUserPwd");
                Intent intent=new Intent(this,StartActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                //删除头像
                //退出
                break;
            case R.id.setting1_rl_feedback:
                openActivity(FeedbackActivity.class);
                break;
        }
    }
}
